package filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.annotation.WebInitParam;

import java.io.IOException;

@WebFilter(filterName = "charseFilter",urlPatterns = "/user/*",initParams = @WebInitParam(name = "charset",value = "UTF-8"))
public class CharseFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        FilterRegistration charseFilter = request.getServletContext().getFilterRegistration("charseFilter");
        String charset = charseFilter.getInitParameter("charset");
        response.setContentType("application/json;charset="+charset);

        chain.doFilter(request, response);
    }
}
